//
//  TopTabBarView.swift
//  MyCloset
//
//  Created by 牟好好 on 2024/11/7.
//

import SwiftUI

struct TopTabBarView: View {
    @Binding var selectedTab: String
    var tabBarColor: UIColor
    
    var body: some View {
        HStack {
            Picker(selection: $selectedTab) {
                ForEach(clothTypes, id: \.self) { type in
                    Text(type).tag(type)
                }
            } label: {
                Text("")
            }
            .pickerStyle(SegmentedPickerStyle())
        }
        .padding(.horizontal)
        .onAppear {
            UISegmentedControl.appearance().selectedSegmentTintColor = tabBarColor
            let attributes: [NSAttributedString.Key : Any] = [
                .foregroundColor : UIColor.white,
                .font : UIFont.systemFont(ofSize: 15, weight: .bold)
            ]
            let normalAttributes: [NSAttributedString.Key : Any] = [
                .font : UIFont.systemFont(ofSize: 15)
            ]
            UISegmentedControl.appearance().setTitleTextAttributes(attributes, for: .selected)
            UISegmentedControl.appearance().setTitleTextAttributes(normalAttributes, for: .normal)
        }
    }
}

#Preview {
    TopTabBarView(selectedTab: .constant("上装"), tabBarColor: .red)
}

#Preview {
    TopTabBarView(selectedTab: .constant("上装"), tabBarColor: .blue)
        .preferredColorScheme(.dark)
}
